
/**
 * @description: 全局数据池
 */
import { washFaceWordList } from './Part1/chapter1/washFace.js'
import { sleepWordList } from './Part1/chapter1/sleep.js'
import { cookWordList } from './Part1/chapter1/cook.js'
import { monthWorldList } from './Part1/chapter1/month.js'
import { bodyWordList } from './Part1/chapter1/body.js'

import { computerBlock1 } from './computer/block1.js'
import { computerBlock2 } from './computer/block2.js'
import { computerBlock3 } from './computer/block3.js'
import { computerBlock4 } from './computer/block4.js'
import { computerBlock5 } from './computer/block5.js'
import { computerBlock6 } from './computer/block6.js'
import { computerBlock7 } from './computer/block7.js'
import { computerBlock8 } from './computer/block8.js'

import { otherBlock1 } from './other/block1.js'
import { otherBlock2 } from './other/block2.js'
import { otherBlock3 } from './other/block3.js'
import { otherBlock4 } from './other/block4.js'
import { otherBlock5 } from './other/block5.js'

import { phraseBlock1 } from './phrase/block1.js'

/** @description 目录
Array<{
	title: string,
	children: Array<{
		title: string,
		children: Array<{
			id: string,
			title: string
		}>
	}>
}>
*/
export const DirectoryData = [
		{
			title: 'Part I 生活常识与社交篇',
			children: [
				{
					title: 'Chapter 00 其他',
					children: [
						{
							id: 'I-00-1',
							title: 'block 1'
						},
						{
							id: 'I-00-2',
							title: 'block 2'
						},
						{
							id: 'I-00-3',
							title: 'block 3'
						},
						{
							id: 'I-00-4',
							title: 'block 4'
						},
						{
							id: 'I-00-5',
							title: 'block 5'
						},
					]
				},
				{
					title: 'Chapter 0 计算机',
					children: [
						{
							id: 'I-0-1',
							title: 'block 1'
						},
						{
							id: 'I-0-2',
							title: 'block 2'
						},
						{
							id: 'I-0-3',
							title: 'block 3'
						},
						{
							id: 'I-0-4',
							title: 'block 4'
						},
						{
							id: 'I-0-5',
							title: 'block 5'
						},
						{
							id: 'I-0-6',
							title: 'block 6'
						},
						{
							id: 'I-0-7',
							title: 'block 7'
						},
						{
							id: 'I-0-8',
							title: 'block 8'
						}
					]
				},
				{
					title: 'Chapter 1 居家生活',
					children: [
						{
							id: 'I-1-1',
							title: '洗漱打扮'
						},
						{
							id: 'I-1-2',
							title: '睡觉起床'
						}, 
						{
							id: 'I-1-3',
							title: '烹饪'
						},
						{
							id: 'I-1-4',
							title: '月份'
						},
						{
							id: 'I-1-5',
							title: '身体'
						}
					]
				},
				{
					title: 'Chapter 2 短语',
					children: [
						{
							id: 'I-2-1',
							title: 'block 1'
						},
					]
				},
			]
		},
		{
			title: 'Part II 旅游篇',
			children: [
				{
					title: 'Chapter 1 行前事宜',
					children: []
				},
				{
					title: 'Chapter 2 上飞机前',
					children: []
				},
			]
		}
	]
	
	/** @description 所有单词
	Array<{
		id: string,
		wordList: Array<{
			en: string,
			zh: string,
			ph?: string,
			eg: Array<{
				en: string,
				zh: string
			}>
		}>
	}>
	*/
	export const WordData = [
		{
			id: 'I-00-1',
			wordList: otherBlock1,
		},
		{
			id: 'I-00-2',
			wordList: otherBlock2,
		},
		{
			id: 'I-00-3',
			wordList: otherBlock3,
		},
		{
			id: 'I-00-4',
			wordList: otherBlock4,
		},
		{
			id: 'I-00-5',
			wordList: otherBlock5,
		},
		{
			id: 'I-0-1',
			wordList: computerBlock1,
		},
		{
			id: 'I-0-2',
			wordList: computerBlock2,
		},
		{
			id: 'I-0-3',
			wordList: computerBlock3,
		},
		{
			id: 'I-0-4',
			wordList: computerBlock4,
		},
		{
			id: 'I-0-5',
			wordList: computerBlock5
		},
		{
			id: 'I-0-6',
			wordList: computerBlock6
		},
		{
			id: 'I-0-7',
			wordList: computerBlock7
		},
		{
			id: 'I-0-8',
			wordList: computerBlock8
		},
		{
			id: 'I-1-1',
			wordList: washFaceWordList
		}, {
			id: 'I-1-2',
			wordList: sleepWordList
		}, {
			id: 'I-1-3',
			wordList: cookWordList
		}, {
			id: 'I-1-4',
			wordList: monthWorldList
		}, {
			id: 'I-1-5',
			wordList: bodyWordList,
		}, {
			id: 'I-2-1',
			wordList: phraseBlock1
		}
	]
	
	console.log("cookWordList:", cookWordList)
	
	// 收藏的单词
	export const StarData = {
		value: [],
	};
	
	/** @description: 获取收藏的单词数据 */
	export function GetStarWordData() {
		console.log("StarData.value:", StarData.value)
		
		let currentWordData = [];
		for(const item of WordData) {
			for(const wordItem of item.wordList) {
				if(StarData.value.includes(wordItem.en)) {
					currentWordData.push(wordItem);
				}
			}
		}
		
		// 深拷贝当前数据
		currentWordData = JSON.parse(JSON.stringify(currentWordData))
		
		// 当前数据再组装
		currentWordData.forEach(item => {
			item.showAll = false;
			item.eg?.forEach(egItem => egItem.showAll = false);
			
			item.isStar = true;
		})
		
		return currentWordData
	}
	
	/** @description: 获取当前展示的wordData数据 */
	export function GetCurrentWordData(id) {
		console.log(id)
		// 寻找当前菜单对应的数据
		let currentWordData = WordData[0].wordList;
		if(id) {
			const res = WordData.find(item => item.id === id);
			if(res) currentWordData = res.wordList;
		}
		
		// 深拷贝当前数据
		currentWordData = JSON.parse(JSON.stringify(currentWordData))
		
		// 当前数据再组装
		currentWordData.forEach(item => {
			item.showAll = false;
			item.eg?.forEach(egItem => egItem.showAll = false);
			
			if(StarData.value.includes(item.en)) item.isStar = true;
			else item.isStar = false; 
		})
		
		// 当前单词对应的菜单
		let currentMenu = {};
		let hadFont = false;
		for(const item of DirectoryData) {
			if(hadFont) break;
			for(const chapterItem of item.children) {
				if(hadFont) break;
				for(const chapterCildItem of chapterItem.children) {
					if(hadFont) break;
					
					if(chapterCildItem.id === (id ?? WordData[0].id)) {
						currentMenu = chapterCildItem;
					}
				}
			}
		}
		
		return {
			wordData: currentWordData,
			menu: currentMenu,
		}
	}